//Source file: D:\\test\\com\\ce\\pms\\custservice\\model\\CustServiceEventDO.java

package com.ce.pms.custservice.model;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.ce.pms.common.model.SysInfo;
import com.ce.pms.house.model.HouseDomain;
import com.ce.pms.system.custservice.model.CustEventKindDO;
import com.ce.pms.system.custservice.model.CustEventNatureDO;
import com.ce.pms.system.custservice.model.EmergencyDegreeDO;
import com.ce.pms.system.custservice.model.EventRegionDO;
import com.ce.pms.system.custservice.model.SeriousDegreeDO;
import com.sitechasia.webx.core.model.IDomainObject;

/**
 * 实体名称:客服事件 关联数据表:CE_CUST_SERVICE_EVENT
 *
 * @author yandawei
 * @CreateDate:2008-12-8
 */
@Entity
@Table(name = "CE_CUST_SERVICE_EVENT")
public class CustServiceEventDO implements IDomainObject {
	/**
	 *
	 */
	private static final long serialVersionUID = 7638910874561904774L;

	/**
	 * 事件状态:作废
	 */
	public static final String EVENT_STATUS_CANCEL_CODE = "000";

	/**
	 * 事件状态:新建
	 */
	public static final String EVENT_STATUS_NEW_CODE = "001";

	/**
	 * 事件状态:已提交
	 */
	public static final String EVENT_STATUS_SUBMIT_CODE = "002";

	/**
	 * 事件状态:已完成
	 */
	public static final String EVENT_STATUS_COMPLETE_CODE = "003";

	/**
	 * 事件状态:待归档
	 */
	public static final String EVENT_STATUS_ARCHIVING_CODE = "004";

	/**
	 * 事件状态:已归档
	 */
	public static final String EVENT_STATUS_ARCHIVED_CODE = "005";

	/**
	 * 回访状态:待回访
	 */
	public static final String RETURN_VISIT_STATUZ_PREPARE_CODE = "001";

	/**
	 * 回访状态:已回访
	 */
	public static final String RETURN_VISIT_STATUZ_COMPLETE_CODE = "002";

	/**
	 * 阅签状态:待阅签
	 */
	public static final String REVIEWER_STATUZ_PREPARE_CODE = "001";

	/**
	 * 阅签状态:已阅签
	 */
	public static final String REVIEWER_STATUZ_COMPLETE_CODE = "002";

	/**
	 * 抽检状态:已抽检
	 */
	public static final String CHECK_STATUZ_COMPLETE_CODE = "1";

	/**
	 * 抽检状态:未抽检
	 */
	public static final String CHECK_STATUZ_PREPARE_CODE = "0";

	/**
	 * 有效性:001有效
	 */
	public static final String EVENT_VALID_CODE="001";

	/**
	 * 有效性:002待定
	 */
	public static final String EVENT_WAITVALID_CODE="002";

	/**
	 * 有效性:000无效
	 */
	public static final String EVENT_INVALID_CODE="000";

	/**
	 * 客户事件ID
	 */
	@Id
	@GeneratedValue
	@Column(name = "CUST_SERVICE_EVENT_ID")
	private Long keyword;

	/**
	 * 事件编号
	 */
	@Column(name = "EVENT_NO", length = 10)
	private String eventNo;

	/**
	 * 详细地址
	 */
	@Column(name = "FULL_ADDRESS", length = 100)
	private String fullAddress;

	/**
	 * 联系人
	 */
	@Column(name = "CONTACT", nullable = false, length = 36)
	private String contact;

	/**
	 * 房号
	 */
	@Column(name = "HOUSE_NUMBER", length = 36)
	private String houseNumber;

	/**
	 * 房间ID
	 */
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="HOUSE_ID")
	private HouseDomain house;

	/**
	 * 联系电话
	 */
	@Column(name = "LINK_PHONE", length = 30)
	private String linkPhone;

	/**
	 * 客户姓名
	 */
	@Column(name = "OWNERS", length = 36)
	private String owners;

	/**
	 * 预约时间
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "APPOINTMENT")
	private Date appointment;

	/**
	 * 事件内容
	 */
	@Column(name = "EVENT_CONTENT", nullable = false, length = 200)
	private String eventContent;

	/**
	 * 有效性:001有效;002待定;000无效
	 */
	@Column(name = "VALIDITY", nullable = false, length = 3)
	private String validity;

	/**
	 * 备注
	 */
	@Column(name = "REMARK", length = 200)
	private String remark;

	/**
	 * 记录人
	 */
	@Column(name = "RECORDER", length = 36)
	private String recorder;

	/**
	 * 记录时间
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "RECORDER_TIME")
	private Date recorderTime;

	/**
	 * 回访状态:001待回访;002已回访
	 */
	@Column(name = "RETURN_VISIT_STATUZ", length = 3)
	private String returnVisitStatuz;

	/**
	 * 阅签状态:001待阅签;002已阅签
	 */
	@Column(name = "REVIEWER_STATUZ", length = 3)
	private String reviewerStatuz;

	/**
	 * 事件状态:001新建;002已提交;003已完成;004待归档;005已归档.000作废
	 */
	@Column(name = "EVENT_STATUZ", length = 3)
	private String eventStatuz;

	/**
	 * 抽检状态 1已抽检;0未抽检
	 */
	@Column(name = "CHECK_STATUZ", length = 1)
	private String checkStatuz = CHECK_STATUZ_PREPARE_CODE;

	/**
	 * 关联数目
	 */
	@Column(name = "RELATIONMAP", nullable = false)
	private Short relationship;

	/**
	 * 事件类型
	 */
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "CUST_EVENT_ASPECT_ID")
	private CustEventKindDO customerServiceEventKindDO;

	/**
	 * 客户事件性质
	 */
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "CUST_EVENT_KIND_ID")
	private CustEventNatureDO customerServiceEventNatureDO;

	/**
	 * 事件区域
	 */
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "EVENT_REGION_ID")
	private EventRegionDO eventRegionDO;

	/**
	 * 严重程度
	 */
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "SERIOUS_DEGREE_ID")
	private SeriousDegreeDO seriousDegreeDO;

	/**
	 * 紧急程度
	 */
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "EMERGENCY_DEGREE_ID")
	private EmergencyDegreeDO emergencyDegreeDO;

	@OneToMany(mappedBy="custServiceEventDO",fetch=FetchType.LAZY)
	private Set<SubmitTaskDO> tasks = new HashSet<SubmitTaskDO>();

	/**
	 * 系统信息
	 */
	@Embedded
	private SysInfo sysInfo;

	/**
	 * 关联事件
	 */
	@ManyToMany(cascade=CascadeType.ALL)
	@org.hibernate.annotations.CollectionOfElements
	@JoinTable(name = "CE_EVENT_RELATION",
			joinColumns = @JoinColumn(name = "MASTER_EVENT_ID"),
			inverseJoinColumns = @JoinColumn(name = "ASSOCIATED_EVENT_ID"))
	private Set<CustServiceEventDO> associateEventSet = new HashSet<CustServiceEventDO>();

	/**
	 * @roseuid 4937AB2D0290
	 */
	public CustServiceEventDO() {

	}

	public CustServiceEventDO(Long keyword)
	{
		  this.keyword = keyword;
	}
	/**
	 * 自定义构造器
	 *
	 * @param contact
	 *            联系人
	 * @param eventContent
	 *            事件内容
	 * @param validity
	 *            是否有效
	 * @param sysInfo
	 *            系统信息
	 * @return com.ce.pms.custservice.model.CustServiceEventDO
	 * @roseuid 49228AC0001F
	 */
	public CustServiceEventDO(String contact, String eventContent,
			String validity,  SysInfo sysInfo) {
		this.contact = contact;
		this.eventContent = eventContent;
		this.validity = validity;
		this.relationship = new Short("0");
		this.sysInfo = sysInfo;
	}

	/***
	 *  设置事件状态"已新建" eventStatuz=001
	 *  @author gaosong
	 */
	public void setEStatuzNew(){
		setEventStatuz(EVENT_STATUS_NEW_CODE);
	}

	/**
	 * 设置事件状态"已提交" eventStatuz=002
	 *
	 * @roseuid 49228C1003B9
	 */
	public void setEStatuzSubmit() {
		setEventStatuz(EVENT_STATUS_SUBMIT_CODE);
	}

	/**
	 * 设置事件状态"已完成" eventStatuz=003
	 *
	 * @roseuid 49280DAD009C
	 */
	public void setEStatuzComplete() {
		setEventStatuz(EVENT_STATUS_COMPLETE_CODE);
	}

	/**
	 * 设置事件状态"待归档" eventStatuz=004
	 *
	 * @roseuid 4923D70B0203
	 */
	public void setEStatuzWaitingArchivism() {
		setEventStatuz(EVENT_STATUS_ARCHIVING_CODE);
	}

	/**
	 * 设置事件状态"已归档" eventStatuz=005
	 *
	 * @roseuid 4923D66C01B5
	 */
	public void setEStatuzHasArchivismed() {
		setEventStatuz(EVENT_STATUS_ARCHIVED_CODE);
	}

	/**
	 * 设置事件状态"作废" eventStatuz=000
	 *
	 * @roseuid 4923C8FC0290
	 */
	public void setEStatuzLogicDele() {
		setEventStatuz(EVENT_STATUS_CANCEL_CODE);
	}

	/**
	 * 设置回访状态"待回访" returnVisitStatuz=001
	 *
	 * @roseuid 4923DAF600DA
	 */
	public void setRVStatuzWaitingReturnVisit() {
		setReturnVisitStatuz(RETURN_VISIT_STATUZ_PREPARE_CODE);
	}

	/**
	 * 设置回访状态"已回访" returnVisitStatuz=002
	 *
	 * @roseuid 4923DBB9009C
	 */
	public void setRVStatuzHasReturnVisited() {
		setReturnVisitStatuz(RETURN_VISIT_STATUZ_COMPLETE_CODE);
	}

	/**
	 * 设置领导阅签状态"待阅签" reviewerStatuz=001
	 *
	 * @roseuid 4923DC02038A
	 */
	public void setRStatuzWaitingSignRead() {
		setReviewerStatuz(REVIEWER_STATUZ_PREPARE_CODE);
	}

	/**
	 * 设置领导阅签状态"已阅签" reviewerStatuz=002
	 *
	 * @roseuid 4923DC6B03A9
	 */
	public void setRStatuzHasSignReaded() {
		setReviewerStatuz(REVIEWER_STATUZ_COMPLETE_CODE);
	}

	/**
	 * 设置是否抽检"已抽检" checkStatuz=1
	 *
	 * @roseuid 4924C77B02FD
	 */
	public void setCStatuzHasChecked() {
		setCheckStatuz(CHECK_STATUZ_COMPLETE_CODE);
	}

	/**
	 * 判断事件是否允许修改 1. 当EventStatuz=001或者EventStatuz=004时,返回true.
	 * 否则返回false
	 *
	 * @return Boolean
	 * @roseuid 4924F673035B
	 */
	public Boolean isAllowUpdate() {
		if (EVENT_STATUS_NEW_CODE.equals(getEventStatuz())
				|| EVENT_STATUS_ARCHIVING_CODE.equals(getEventStatuz()))
			return true;
		else
			return false;

	}

	/**
	 * 功能描述: 当事件状态EventStatuz=003或EventStatuz=004时,返回ture,否则返回false <br>
	 * @return
	 * Create author:yandawei <br>
	 * Create on:2008-12-26  <br>
	 * Edit author:  高嵩<br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public boolean isAllowReturnVisit(){
		if(!getValidity().equals(EVENT_INVALID_CODE)
				&& (EVENT_STATUS_ARCHIVING_CODE.equals(getEventStatuz())
						||EVENT_STATUS_COMPLETE_CODE.equals(getEventStatuz()) ))
			return true;
		return false;

	}

	/***
	 * 功能描述:  判断是否充许作废回访
	 * 当事件状态为EventStatuz=003或EventStatuz=004时返回ture,否则返回false<br>
	 * @return
	 * Create author:高嵩 <br>
	 * Create on:2009-1-4  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public boolean isAllowSetAsideReturnVisit(){
		if (EVENT_STATUS_ARCHIVING_CODE.equals(getEventStatuz())
				|| EVENT_STATUS_COMPLETE_CODE.equals(getEventStatuz()))
			return true;
		return false;
	}


	/***
	 * 功能描述:  当事件状态为EventStatuz=003或者为待归档并且阅签状态reviwerStatuz!=002时,返回ture<br>
	 * @return
	 * Create author:高嵩 <br>
	 * Create on:2009-1-4  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public boolean isAllowReadView(){
		if (!REVIEWER_STATUZ_COMPLETE_CODE.equals(getReviewerStatuz())
				&& (EVENT_STATUS_COMPLETE_CODE.equals(getEventStatuz())
						|| EVENT_STATUS_ARCHIVING_CODE.equals(getEventStatuz())))
			return true;
		return false;
	}
	/**
	 * 功能描述:  是否允许抽检当回访状态为returnVisitStatuz=002时,返回ture;否则返回false<br>
	 * @return
	 * Create author:yandawei <br>
	 * Create on:2008-12-22  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public boolean isAllowCheck(){
		if(RETURN_VISIT_STATUZ_COMPLETE_CODE.equals(getReturnVisitStatuz())){
			return true;
		}
		return false;
	}

	/**
	 * 是否允许事件作废
			1.当事件状态为新建EventStatuz=001时返回ture
			2.当事件状态为待归档EventStatuz=004,并且validity=000时返回true.
			3.其他返回false
	 *
	 * @return Boolean
	 * @roseuid 49281BC302EE
	 */
	public Boolean isAllowCustomerServiceEventSetAside() {
		if(EVENT_STATUS_NEW_CODE.equals(getEventStatuz())){
			return true;
		}
		else if (EVENT_STATUS_ARCHIVING_CODE.equals(getEventStatuz()) && EVENT_INVALID_CODE.equals(getValidity())){
			return true;
		}else{
			return false;
		}
	}

	/**
	 * 功能描述: 增加关系数目<br>
	 *
	 * @return Create author:yandawei <br>
	 *         Create on:2008-12-8 <br>
	 *         Edit author: <br>
	 *         Edit on: <br>
	 *         Why: <br>
	 */
	public Short increaseRelationship() {
		return this.relationship =(short) (this.relationship +1);
	}

	/**
	 * 功能描述:判断是否允许归档:
			1.当事件状态为新建eventStatuz=001或者eventStatuz=004时返回true,否则返回false <br>
	 * @return
	 * Create author:yandawei <br>
	 * Create on:2008-12-22  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public boolean isAllowArchivism(){
		if(EVENT_STATUS_NEW_CODE.equals(getEventStatuz()) || EVENT_STATUS_ARCHIVING_CODE.equals(getEventStatuz())){
			return true;
		}
		return false;
	}

	/**
	 * 功能描述:  重置抽检状态为空CStatuz=""<br>
	 *
	 * Create author:yandawei <br>
	 * Create on:2008-12-22  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void resetCStatuz(){
		this.setCheckStatuz("");
	}

	/**
	 * 功能描述: 删除关系数目<br>
	 *
	 * @return Create author:yandawei <br>
	 *         Create on:2008-12-8 <br>
	 *         Edit author: <br>
	 *         Edit on: <br>
	 *         Why: <br>
	 */
	public Short decreaseRelationship() {
		return this.relationship=(short) (this.relationship -1);
	}

	/***
	 * 功能描述:  关联事件<br>
	 * @param customerServiceEvent
	 * Create author:yandawei <br>
	 * Create on:2008-12-9  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void addAssociateEvent(CustServiceEventDO customerServiceEvent) {
		this.getAssociateEventSet().add(customerServiceEvent);
	}

	/**
	 * 功能描述:是否允许新增派工单。  <br>
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-12-30  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public Boolean isAllowAddDispatchForm(){
		if ((CustServiceEventDO.EVENT_VALID_CODE.equals(this.validity) || CustServiceEventDO.EVENT_WAITVALID_CODE.equals(this.validity))
				&& (CustServiceEventDO.EVENT_STATUS_NEW_CODE.equals(this.eventStatuz)
						|| CustServiceEventDO.EVENT_STATUS_SUBMIT_CODE.equals(this.eventStatuz)
				)) {
			return true;
		}
		return false;
	}

	/**
	 * 功能描述:  解除事件<br>
	 * @param customerServiceEvent
	 * Create author:yandawei <br>
	 * Create on:2008-12-9  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void removeAssociateEvent(CustServiceEventDO customerServiceEvent) {
		this.getAssociateEventSet().remove(customerServiceEvent);
	}

	public Date getAppointment() {
		return appointment;
	}

	public void setAppointment(Date appointment) {
		this.appointment = appointment;
	}

	public String getCheckStatuz() {
		return checkStatuz;
	}

	public void setCheckStatuz(String checkStatuz) {
		this.checkStatuz = checkStatuz;
	}

	public String getContact() {
		return contact;
	}

	public void setContact(String contact) {
		this.contact = contact;
	}

	public String getEventContent() {
		return eventContent;
	}

	public void setEventContent(String eventContent) {
		this.eventContent = eventContent;
	}

	public String getEventNo() {
		return eventNo;
	}

	public void setEventNo(String eventNo) {
		this.eventNo = eventNo;
	}

	public String getEventStatuz() {
		return eventStatuz;
	}

	public void setEventStatuz(String eventStatuz) {
		this.eventStatuz = eventStatuz;
	}

	public String getFullAddress() {
		return fullAddress;
	}

	public void setFullAddress(String fullAddress) {
		this.fullAddress = fullAddress;
	}

	public String getHouseNumber() {
		return houseNumber;
	}

	public void setHouseNumber(String houseNumber) {
		this.houseNumber = houseNumber;
	}

	public Long getKeyword() {
		return keyword;
	}

	public void setKeyword(Long keyword) {
		this.keyword = keyword;
	}

	public String getLinkPhone() {
		return linkPhone;
	}

	public void setLinkPhone(String linkPhone) {
		this.linkPhone = linkPhone;
	}

	public String getOwners() {
		return owners;
	}

	public void setOwners(String owners) {
		this.owners = owners;
	}

	public String getRecorder() {
		return recorder;
	}

	public void setRecorder(String recorder) {
		this.recorder = recorder;
	}

	public Date getRecorderTime() {
		return recorderTime;
	}

	public void setRecorderTime(Date recorderTime) {
		this.recorderTime = recorderTime;
	}

	public Short getRelationship() {
		return relationship;
	}

	public void setRelationship(Short relationship) {
		this.relationship = relationship;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getReturnVisitStatuz() {
		return returnVisitStatuz;
	}

	public void setReturnVisitStatuz(String returnVisitStatuz) {
		this.returnVisitStatuz = returnVisitStatuz;
	}

	public String getReviewerStatuz() {
		return reviewerStatuz;
	}

	public void setReviewerStatuz(String reviewerStatuz) {
		this.reviewerStatuz = reviewerStatuz;
	}

	public SysInfo getSysInfo() {
		return sysInfo;
	}

	public void setSysInfo(SysInfo sysInfo) {
		this.sysInfo = sysInfo;
	}

	public Set<CustServiceEventDO> getAssociateEventSet() {
		return associateEventSet;
	}

	public void setAssociateEventSet(Set<CustServiceEventDO> associateEventSet) {
		this.associateEventSet = associateEventSet;
	}

	public EmergencyDegreeDO getEmergencyDegreeDO() {
		return emergencyDegreeDO;
	}

	public void setEmergencyDegreeDO(EmergencyDegreeDO emergencyDegreeDO) {
		this.emergencyDegreeDO = emergencyDegreeDO;
	}

	public EventRegionDO getEventRegionDO() {
		return eventRegionDO;
	}

	public void setEventRegionDO(EventRegionDO eventRegionDO) {
		this.eventRegionDO = eventRegionDO;
	}

	public SeriousDegreeDO getSeriousDegreeDO() {
		return seriousDegreeDO;
	}

	public void setSeriousDegreeDO(SeriousDegreeDO seriousDegreeDO) {
		this.seriousDegreeDO = seriousDegreeDO;
	}

	public String getValidity() {
		return validity;
	}

	public void setValidity(String validity) {
		this.validity = validity;
	}

	public HouseDomain getHouse() {
		return house;
	}

	public void setHouse(HouseDomain house) {
		this.house = house;
	}

	/**
	 * @return the customerServiceEventKindDO
	 */
	public CustEventKindDO getCustomerServiceEventKindDO() {
		return customerServiceEventKindDO;
	}

	/**
	 * @param customerServiceEventKindDO the customerServiceEventKindDO to set
	 */
	public void setCustomerServiceEventKindDO(
			CustEventKindDO customerServiceEventKindDO) {
		this.customerServiceEventKindDO = customerServiceEventKindDO;
	}

	/**
	 * @return the customerServiceEventNatureDO
	 */
	public CustEventNatureDO getCustomerServiceEventNatureDO() {
		return customerServiceEventNatureDO;
	}

	/**
	 * @param customerServiceEventNatureDO the customerServiceEventNatureDO to set
	 */
	public void setCustomerServiceEventNatureDO(
			CustEventNatureDO customerServiceEventNatureDO) {
		this.customerServiceEventNatureDO = customerServiceEventNatureDO;
	}

	public Set<SubmitTaskDO> getTasks() {
		return tasks;
	}

	public void setTasks(Set<SubmitTaskDO> tasks) {
		this.tasks = tasks;
	}

}
